﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Navigation;
using Microsoft.Phone.Controls;
using Microsoft.Phone.Shell;
using PhoneApp1.Resources;

using Windows.Networking.Sockets;
using Windows.Networking;
using System.Threading.Tasks;
using Windows.Storage.Streams;
using System.Text;

using NovoGenus.Sockets.Http;

namespace PhoneApp1
{
    public partial class MainPage : PhoneApplicationPage
    {

        private string xmlUrl1 = "www.abs-cbnnews.com/nation/feed";
        private string xmlUrl2 = "www.abs-cbnnews.com";
        private string xmlUrl3 = "news.yahoo.com";
        private string xmlUrl4 = "www.cfax1070.com";
        private string xmlUrl5 = "origin1.ctv.ca";
        private string xmlUrl6 = "www.ctv.ca";



        // Constructor
        public MainPage()
        {
            InitializeComponent();
            // Calls to TaskOfTResult_MethodAsync
            //Task<int> returnedTaskTResult = TaskOfTResult_MethodAsync();
            //int intResult = await returnedTaskTResult;
            //// or, in a single statement
            //int intResult = await TaskOfTResult_MethodAsync();


            testasync();
           
            //httpClient.ConnectAsync().ContinueWith((task) =>
            //{
            //    Task<HttpResponse> response = httpClient.GetResponseAsync();
                
            //    .ContinueWith((taskresponse) => {
            //        data = taskresponse.Result.Body;
            //    });
            //});
           // HttpClient httpClient = new HttpClient(xmlUrl6, "/");
            ShowStatus("waiting...");
        }

        public async void testasync()
        {
            HttpClient httpClient = new HttpClient(xmlUrl6, "/");
            string data = "";
            ShowStatus("in here: 1");
            await httpClient.ConnectAsync();
            await httpClient.GetResponseAsync();
            string message = await httpClient.TestAsync();
            ShowStatus(message);
            ShowStatus(httpClient.Response.Body);
            ShowStatus("in here: 2");
        }

        //async Task<int> TaskOfTResult_MethodAsync()
        //{
        //    int hours;
        //    // . . .
        //    // Return statement specifies an integer result.
        //    return hours;
        //}


     

        private void ShowStatus(string message)
        {
            TextBlock textblock = new TextBlock();
            textblock.Text = message;
            stackpanel1.Children.Insert(stackpanel1.Children.Count, textblock);
        }


       

        // Sample code for building a localized ApplicationBar
        //private void BuildLocalizedApplicationBar()
        //{
        //    // Set the page's ApplicationBar to a new instance of ApplicationBar.
        //    ApplicationBar = new ApplicationBar();

        //    // Create a new button and set the text value to the localized string from AppResources.
        //    ApplicationBarIconButton appBarButton = new ApplicationBarIconButton(new Uri("/Assets/AppBar/appbar.add.rest.png", UriKind.Relative));
        //    appBarButton.Text = AppResources.AppBarButtonText;
        //    ApplicationBar.Buttons.Add(appBarButton);

        //    // Create a new menu item with the localized string from AppResources.
        //    ApplicationBarMenuItem appBarMenuItem = new ApplicationBarMenuItem(AppResources.AppBarMenuItemText);
        //    ApplicationBar.MenuItems.Add(appBarMenuItem);
        //}
    }
}